Skip to contentSkip to conversation

Rockchip soc theamal driver

PATCH Superseded Caesar Wang 7 participants 15 messages Aug 28, 2014 – Aug 30, 2014

Subsystems (4)

v3 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v3 cover Rockchip soc theamal driver

Changes in v3:(add dts configure)
* address comments from Dmitry Torokhov and Arnd Bergmann:
- fix clock-names in rockchip-thermal.txt
- remove rockchip_thermal_control() in rockchip_set_mode()
- fix some code style.
- add dts configure.

Changes in v2:
* address comments from Heiko Stubner:
- fix dt-bindings in rockchip-thermal.txt
- remove Author mark
- rename TSADC_XXX->TSADCV2_XXX,it eill ready to merge compatible other SoCs.
- fix a identation
- remove clk_set_rate(),it's no necessary.
- fix the SIMPLE_DEV_PM_OPS() function style.

Tested On rk3288 SDK board.

Caesar Wang (4):
thermal: rockchip: add driver for thermal
dt-bindings: document Rockchip thermal
ARM: dts: add main Thermal info to rk3288
ARM: dts: enable Thermal on rk3288-evb board

 .../bindings/thermal/rockchip-thermal.txt          |  20 +
 arch/arm/boot/dts/rk3288-evb.dtsi                  |   7 +
 arch/arm/boot/dts/rk3288.dtsi                      |  18 +
 drivers/thermal/Kconfig                            |   9 +
 drivers/thermal/Makefile                           |   1 +
 drivers/thermal/rockchip_thermal.c                 | 669 +++++++++++++++++++++
 6 files changed, 724 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
 create mode 100644 drivers/thermal/rockchip_thermal.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/4 thermal: rockchip: add driver for thermal

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

If you find that the temperature High in a period of time, an interrupt is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

---
 drivers/thermal/Kconfig            |   9 +
 drivers/thermal/Makefile           |   1 +
 drivers/thermal/rockchip_thermal.c | 669 +++++++++++++++++++++++++++++++++++++
 3 files changed, 679 insertions(+)
 create mode 100644 drivers/thermal/rockchip_thermal.c
drivers/thermal/Kconfig +9 -0
index f9a1386..a00aa1e 100644
@@ -133,6 +133,15 @@ config SPEAR_THERMAL
 	  Enable this to plug the SPEAr thermal sensor driver into the Linux
 	  thermal framework.
 
+config ROCKCHIP_THERMAL
+	tristate "Rockchip thermal driver"
+	depends on ARCH_ROCKCHIP
+	help
+	  Support for Temperature Sensor ADC (TS-ADC) found on Rockchip SoCs.
+	  It supports one critical trip point and one passive trip point.  The
+	  cpufreq is used as the cooling device to throttle CPUs when the
+	  passive trip is crossed.
+
 config RCAR_THERMAL
 	tristate "Renesas R-Car thermal driver"
 	depends on ARCH_SHMOBILE || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index de0636a..b48b817 100644
@@ -19,6 +19,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL)	+= cpu_cooling.o
 
 # platform thermal drivers
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
+obj-$(CONFIG_ROCKCHIP_THERMAL) 	+= rockchip_thermal.o
 obj-$(CONFIG_RCAR_THERMAL)	+= rcar_thermal.o
 obj-$(CONFIG_KIRKWOOD_THERMAL)  += kirkwood_thermal.o
 obj-y				+= samsung/
drivers/thermal/rockchip_thermal.c new file +669 -0

669 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Quoted 8 lines · On Thursday 28 August 2014 08:59:19 Caesar Wang wrote:

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

Quoted 6 lines

If you find that the temperature High in a period of time, an interrupt is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

Hi Caesar,

After looking at the driver (last time I only received the patch for the binding), I have a more general comment:

This looks like a general-purpose ADC device, not an IP block that is specific to thermal management. The binding looks ok for that purpose but should probably be moved into Documentation/devicetree/bindings/iio/adc/ as a minor change.

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

I've put the IIO maintainer on Cc in this mail, maybe Jonathan or someone else on the linux-iio mailing list has some extra insight.

Arnd

#3 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Ceasar and Arnd,

Quoted 18 lines · Arnd Bergmann
Quoted 8 lines · On Thursday 28 August 2014 08:59:19 Caesar Wang wrote:

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

Quoted 6 lines

If you find that the temperature High in a period of time, an interrupt is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

Hi Caesar,

Quoted 8 lines

After looking at the driver (last time I only received the patch for the binding), I have a more general comment:

This looks like a general-purpose ADC device, not an IP block that is specific to thermal management. The binding looks ok for that purpose but should probably be moved into Documentation/devicetree/bindings/iio/adc/ as a minor change.

I agree with Arnd's point here. It makes sense to me to have this driver under the IIO umbrella.

Quoted 6 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

Quoted 4 lines

I've put the IIO maintainer on Cc in this mail, maybe Jonathan or someone else on the linux-iio mailing list has some extra insight.

Arnd

Cheers,

Eduardo

maintainer
#4 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 27 lines

Ceasar and Arnd,

Quoted 24 lines · Arnd Bergmann
Quoted 10 lines · On Thursday 28 August 2014 08:59:19 Caesar Wang wrote:

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software
writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

Quoted 7 lines

If you find that the temperature High in a period of time, an interrupt is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

Hi Caesar,

After looking at the driver (last time I only received the patch for the binding), I have a more general comment:

Quoted 7 lines
Quoted 4 lines

This looks like a general-purpose ADC device, not an IP block that is specific to thermal management. The binding looks ok for that purpose but should probably be moved into Documentation/devicetree/bindings/iio/adc/ as a minor change.

I agree with Arnd's point here. It makes sense to me to have this driver under the IIO umbrella.

interesting suggestion :-)

I've just taken another look at the registers of the ts-adc on the rk3066 which is completely different from the rk3288 one. Interestingly the rk3066 one is "just" another saradc IP, so for this one it would really make sense.

Quoted 8 lines
Quoted 5 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Also when getting the temperature, Caesar's driver compares it to its trip points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see it.

Heiko

#5 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Quoted 16 lines · On Thursday 28 August 2014 18:11:43 Heiko St?bner wrote:

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 8 lines
Quoted 5 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Quoted 6 lines

Also when getting the temperature, Caesar's driver compares it to its trip points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see it.

Eduardo earlier today replied to an email about a generic driver for thermal, which was posted in February but hasn't been merged. See https://lkml.org/lkml/2014/2/5/810

There may be a newer version of this patch, which I haven't found.

Arnd

#6 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Arnd & Heiko & Eduardo,

OK. Maybe you are right.

This driver should be put into drivers/iio/adc/* , Anyway,I will re-edit it ASAP.

? 2014/8/29 0:16, Arnd Bergmann ??:

Quoted 31 lines · On Thursday 28 August 2014 18:11:43 Heiko St?bner wrote:
Quoted 14 lines

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 7 lines
Quoted 5 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Quoted 6 lines

Also when getting the temperature, Caesar's driver compares it to its trip points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see it.

Eduardo earlier today replied to an email about a generic driver for thermal, which was posted in February but hasn't been merged. See https://lkml.org/lkml/2014/2/5/810

There may be a newer version of this patch, which I haven't found.

Arnd

Signature · 2 lines
Best regards,
Caesar
maintainer Tested-by
#7 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Hi Caesar,

Am Freitag, 29. August 2014, 03:36:36 schrieb Caesar Wang:

Quoted 6 lines

Arnd & Heiko & Eduardo,

OK. Maybe you are right.

This driver should be put into drivers/iio/adc/* , Anyway,I will re-edit it ASAP.

I pieced together an example on how this could look, if you need inspiration.

As I've written, the tsadc on the rk3066 is simply another saradc, so it was easy to build a usable example with it, which you can find in my devel/workbench branch [0].

Things to note, the adc values are converted to voltages instead of the "code"-values listed in the TRM [formula: (code * vref_mv) >> 12)] and the temperatures are listed in millikelvin (C+273150) as expected by the pending iio-thermal driver.

@Courtney: (not sure how to reply to the old thread from february) the only issue I found was the unit of the voltages. The binding doc lists them as uV, while iio (and the driver itself) expect to use mV.

Otherwise the iio-thermal driver:

Heiko

[0] https://github.com/mmind/linux-rockchip/commits/devel/workbench
(recent commits till "thermal: add generic IIO channel thermal sensor driver")

Quoted 37 lines · Arnd Bergmann
Quoted 36 lines · On Thursday 28 August 2014 18:11:43 Heiko Stübner wrote:
Quoted 19 lines

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 10 lines
Quoted 7 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c
file, and a smaller thermal driver that uses the iio in-kernel interfaces,
ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Quoted 8 lines

Also when getting the temperature, Caesar's driver compares it to its trip
points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see
it.

Eduardo earlier today replied to an email about a generic driver for thermal, which was posted in February but hasn't been merged. See https://lkml.org/lkml/2014/2/5/810

There may be a newer version of this patch, which I haven't found.

Arnd

#8 lore raw

Re: Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

In reply to Heiko Stübner

Hi Heiko,

The TS-ADC on RK3288 has two component, a tsadc and a tsadc controller. The tsadc controller is similar like the thermal manager unit on other SOCs. We followed the naming of 3066, but not named as the Thermal Manager.

Moreover,there is only one set of apb registers to access the tsadc controller,and the tsadc is controlled by the tsadc controller,could not access directly. If we write a general tsadc driver by accessed tsadc controller registers, and it hardly to write a driver for the tsadc controller.

So, I do not agree to write a generic adc driver for the rk3288-tsadc.

Yifeng Zhao

发件人: HeikoStübner
发送时间: 2014-08-29 00:11
收件人: Eduardo Valentin
抄送: Arnd Bergmann; Caesar Wang; rui.zhang; grant.likely; robh+dt; linux-kernel; linux-pm; linux-arm-kernel; devicetree; linux-doc; huangtao; cf; dianders; dtor; zyw; addy.ke; dmitry.torokhov; zhaoyifeng; linux-iio; Jonathan Cameron 主题: Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 27 lines

Ceasar and Arnd,

Quoted 24 lines · Arnd Bergmann
Quoted 10 lines · On Thursday 28 August 2014 08:59:19 Caesar Wang wrote:

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software
writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

Quoted 7 lines

If you find that the temperature High in a period of time, an interrupt is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

Hi Caesar,

After looking at the driver (last time I only received the patch for the binding), I have a more general comment:

Quoted 7 lines
Quoted 4 lines

This looks like a general-purpose ADC device, not an IP block that is specific to thermal management. The binding looks ok for that purpose but should probably be moved into Documentation/devicetree/bindings/iio/adc/ as a minor change.

I agree with Arnd's point here. It makes sense to me to have this driver under the IIO umbrella.

interesting suggestion :-)

I've just taken another look at the registers of the ts-adc on the rk3066 which is completely different from the rk3288 one. Interestingly the rk3066 one is "just" another saradc IP, so for this one it would really make sense.

Quoted 8 lines
Quoted 5 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces, ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Also when getting the temperature, Caesar's driver compares it to its trip points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see it.

Heiko

#9 lore raw

Re: Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Hello Zhao,

Quoted 11 lines · ???

Hi Heiko?

The TS-ADC on RK3288 has two component, a tsadc and a tsadc controller.
The tsadc controller is similar like the thermal manager unit on other SOCs. We followed the naming of 3066, but not named as the Thermal Manager.

Moreover,there is only one set of apb registers to access the tsadc
controller,and the tsadc is controlled by the tsadc controller,could not access directly. If we write a general tsadc driver by accessed tsadc controller registers, and it hardly to write a driver for the tsadc controller.

As suggested by Arnd, you can use the generic driver as interface between thermal framework and IIO layer. The driver you are going to write to your ADC is going to be in the IIO subsystem. The only difference is that the generic driver would work for any ADC driver in the IIO subsystem.
https://lkml.org/lkml/2014/2/5/810

In fact, there is already a generic driver. We just need to get it up to date. I see some testing has been already done, and results sound promising.

Quoted 87 lines

So, I do not agree to write a generic adc driver for the rk3288-tsadc.

________________________________
Yifeng Zhao

???? HeikoSt?bner
????? 2014-08-29 00:11
???? Eduardo Valentin
??? Arnd Bergmann; Caesar Wang; rui.zhang; grant.likely; robh+dt; linux-kernel; linux-pm; linux-arm-kernel; devicetree; linux-doc; huangtao; cf; dianders; dtor; zyw; addy.ke; dmitry.torokhov; zhaoyifeng; linux-iio; Jonathan Cameron
??? Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Am Donnerstag, 28. August 2014, 10:37:35 schrieb Eduardo Valentin:

Quoted 28 lines

Ceasar and Arnd,

Quoted 25 lines · Arnd Bergmann
Quoted 10 lines · On Thursday 28 August 2014 08:59:19 Caesar Wang wrote:

Thermal is TS-ADC Controller module supports user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software
writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output,and the results Were checked.

Quoted 8 lines

If you find that the temperature High in a period of time, an interrupt
is generated to the processor down-measures taken;if the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

Hi Caesar,

After looking at the driver (last time I only received the patch for the binding), I have a more general comment:

Quoted 7 lines
Quoted 4 lines

This looks like a general-purpose ADC device, not an IP block that is specific to thermal management. The binding looks ok for that purpose but should probably be moved into Documentation/devicetree/bindings/iio/adc/ as a minor change.

I agree with Arnd's point here. It makes sense to me to have this driver under the IIO umbrella.

interesting suggestion :-)

I've just taken another look at the registers of the ts-adc on the rk3066 which is completely different from the rk3288 one. Interestingly the rk3066 one
is "just" another saradc IP, so for this one it would really make sense.

Quoted 9 lines
Quoted 6 lines

On the driver side, I believe the correct way to deal with this setup is to split your driver into a generic drivers/iio/adc/rockchips-tsadc.c file, and a smaller thermal driver that uses the iio in-kernel interfaces,
ideally one that is independent of the underlying hardware and can work on any ADC implementation.

Agreed. If you can write such interface and make your driver to work in such way, that would be great.

But I currently don't see how you would model the temperature handling parts from a generic thermal driver to a generic adc driver for the rk3288-tsadc.

I guess the general temperature irq handling would use iio-triggers? But how does the target temperature get into the TSADC_COMP1_INT register.

Also when getting the temperature, Caesar's driver compares it to its trip points and sets the next trip point depending on the current temperature (passive <-> critical) in rockchip_get_temp.

Maybe there is some completely easy way for this, but currently I don't see it.

Heiko

Signature · 1 line
Eduardo Bezerra Valentin
#10 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Dear Eduardo Bezerra Valentin:

? 2014?08?29? 19:39, edubezval at gmail.com ??:

Quoted 21 lines

Hello Zhao,

Quoted 11 lines · ???

Hi Heiko?

The TS-ADC on RK3288 has two component, a tsadc and a tsadc controller.
The tsadc controller is similar like the thermal manager unit on other SOCs. We followed the naming of 3066, but not named as the Thermal Manager.

Moreover,there is only one set of apb registers to access the tsadc
controller,and the tsadc is controlled by the tsadc controller,could not access directly. If we write a general tsadc driver by accessed tsadc controller registers, and it hardly to write a driver for the tsadc controller.

As suggested by Arnd, you can use the generic driver as interface between thermal framework and IIO layer. The driver you are going to write to your ADC is going to be in the IIO subsystem. The only difference is that the generic driver would work for any ADC driver in the IIO subsystem.
https://lkml.org/lkml/2014/2/5/810

Quoted 3 lines

In fact, there is already a generic driver. We just need to get it up to date. I see some testing has been already done, and results sound promising.

This iio_thermal driver only support get temperature from the ADC IIO channel.
It dose not support any advanced feature such as configure the temperature when system should be reset.
So if we adapt it, we will access the register form both TSADC IIO driver and thermal driver.
I don't thank this is a good ideal.

In fact, we should ignore the "ADC" stuff. This sensor use ADC internal, but it is transparent to software, especially in automatic mode.

Quoted 7 lines
Quoted 7 lines

So, I do not agree to write a generic adc driver for the rk3288-tsadc.

________________________________
Yifeng Zhao

maintainer
#11 lore raw

Re: [PATCH v3 1/4] thermal: rockchip: add driver for thermal

Quoted 27 lines · Huang Tao

Dear Eduardo Bezerra Valentin:

? 2014?08?29? 19:39, edubezval at gmail.com ??:

Quoted 21 lines

Hello Zhao,

Quoted 11 lines · ???

Hi Heiko?

The TS-ADC on RK3288 has two component, a tsadc and a tsadc controller.
The tsadc controller is similar like the thermal manager unit on other SOCs. We followed the naming of 3066, but not named as the Thermal Manager.

Moreover,there is only one set of apb registers to access the tsadc
controller,and the tsadc is controlled by the tsadc controller,could not access directly. If we write a general tsadc driver by accessed tsadc controller registers, and it hardly to write a driver for the tsadc controller.

As suggested by Arnd, you can use the generic driver as interface between thermal framework and IIO layer. The driver you are going to write to your ADC is going to be in the IIO subsystem. The only difference is that the generic driver would work for any ADC driver in the IIO subsystem.
https://lkml.org/lkml/2014/2/5/810

Quoted 3 lines

In fact, there is already a generic driver. We just need to get it up to date. I see some testing has been already done, and results sound promising.

Quoted 7 lines

This iio_thermal driver only support get temperature from the ADC IIO channel.
It dose not support any advanced feature such as configure the temperature when system should be reset.
So if we adapt it, we will access the register form both TSADC IIO driver and thermal driver.
I don't thank this is a good ideal.

Interesting bit of functionality. I agree this doesn't fit overwelmingly well into an iio consumer driver as things currently stand.

Looking briefly at your code, this is basically a threshold interrupt? If so then we do have threshold type event handling in IIO (simply termed events). The snag is that it is the one area that doesn't currently have any in kernel interfaces.

Such an interface would be similar to that used for the buffered data access (raw data stream - we should probably rename that as it isn't always buffered anymore). The nasty bit (as it was with the buffered interface) is writing a reasonably efficient demux that can split out the data to those devices that have registered their interest in it. It would involve some additional code in iio_push_event and some indirection in the code that controls what events are enabled. Actually, you could probably skip this an just squirt all events recieved out through the direct IIO to userspace interface (nothing prevents another process turning more on anyway!). We could event for now specify that any in kernel users might get other events and it is up to them to sanity check them.

We'd also need to add some basic access functions to set limits etc.

I'm afraid the 'events' bit of IIO is one of our least developed elements and is lagging way behind the work done on the main data flows. It's been on the list for a while, particularly as we need it to finish separating the userspace interfaces of IIO from the backend.

So, looking at the wider picture, with a few additions to IIO we can support some ADC based thermal drivers - whether all of them is a bit dependent on whether they have weird and wonderful domain specific hardware (which I might have missed here, but does not seem to be present).

Note this is based on a rather brief scan read so I may well have missed some important details!

Quoted 3 lines

In fact, we should ignore the "ADC" stuff. This sensor use ADC internal, but it is transparent to software, especially in automatic mode.

Is this adc ever used for anything else? If so, then there is your reason to go through the pain of a generic driver.

Jonathan

p.s. I'd never seen the driver Arnd highlighted. Could anyone working on IIO clients cc linux-iio at vger.kernel.org as it's useful to know what people are using the interfaces for (particularly as they might change so it is good to know what is in the pipeline).

Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

So, I do not agree to write a generic adc driver for the rk3288-tsadc.

________________________________
Yifeng Zhao

#12 lore raw

PATCH v3 2/4 dt-bindings: document Rockchip thermal

In reply to Caesar Wang

This add the necessary binding documentation for the thermal found on Rockchip SoCs

---
 .../devicetree/bindings/thermal/rockchip-thermal.txt | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +20 -0
new file mode 100644
index 0000000..1ed4d4c
@@ -0,0 +1,20 @@
+* Temperature Sensor ADC (TSADC) on rockchip SoCs
+
+Required properties:
+- compatible: "rockchip,rk3288-tsadc"
+- reg: physical base address of the controller and length of memory mapped
+       region.
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+	      depends on the interrupt controller.
+- clocks: Must contain an entry for each entry in clock-names.
+- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for
+	       the peripheral clock.
+
+Example:
+tsadc: tsadc at ff280000 {
+	compatible = "rockchip,rk3288-tsadc";
+	reg = <0xff280000 0x100>;
+	interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
+	clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>;
+	clock-names = "tsadc", "apb_pclk";
+};
Signature · 1 line
1.9.1
#13 lore raw

PATCH v3 3/4 ARM: dts: add main Thermal info to rk3288

In reply to Caesar Wang
---
 arch/arm/boot/dts/rk3288.dtsi | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +18 -0
index 36be7bb..3d672e3 100644
@@ -224,6 +224,17 @@
 		status = "disabled";
 	};
 
+	tsadc: tsadc at ff280000 {
+		compatible = "rockchip,rk3288-tsadc";
+		reg = <0xff280000 0x100>;
+		interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>;
+		clock-names = "tsadc", "apb_pclk";
+		pinctrl-names = "default";
+		pinctrl-1 = <&tsadc_int>;
+		status = "disabled";
+	};
+
 	/* NOTE: ohci at ff520000 doesn't actually work on hardware */
 
 	usb_hsic: usb at ff5c0000 {
@@ -611,5 +622,12 @@
 				rockchip,pins = <5 15 3 &pcfg_pull_none>;
 			};
 		};
+
+		tsadc {
+			tsadc_int: tsadc-int {
+				rockchip,pins = <0 10 RK_FUNC_1 &pcfg_pull_up>;
+			};
+		};
+
 	};
 };
Signature · 1 line
1.9.1
#14 lore raw

PATCH v4 4/4 ARM: dts: enable Thermal on rk3288-evb board

In reply to Caesar Wang
---
 arch/arm/boot/dts/rk3288-evb.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/dts/rk3288-evb.dtsi +7 -0
index 2964370..fe85dde 100644
@@ -101,6 +101,13 @@
 	status = "okay";
 };
 
+&tsadc {
+	passive-temp = <80>;
+	critical-temp = <100>;
+	force-shut-temp = <120>;
+	status = "okay";
+};
+
 &pinctrl {
 	buttons {
 		pwrbtn: pwrbtn {
Signature · 1 line
1.9.1